﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Entity;
using System.IO;
using System.Data;

namespace Controller
{
    public partial class Controller_Employee : Component
    {
        Entity_Employee ent_Employ = new Entity_Employee();
        public Controller_Employee()
        {
            InitializeComponent();
        }

        public Controller_Employee(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        public bool Insert_employee(string employeeID, string name, int sex, string birthDay, string personID, string dateOfIssue, string placeOfIssue, string hometown, string email, string mobile, string addressE, string salary, byte[] images, string homePhone, string startupPath)
        {
            byte[] buff = null;
            if (images == null)
            //images = BitConverter.GetBytes(0);
            {
                FileStream files = new FileStream(startupPath + "\\NO_IMG.png", FileMode.Open);
                buff = new byte[files.Length];
                //Doc FileStream fs vua tao o tren vao mang byte[] buff
                files.Read(buff, 0, (int)files.Length);
                images = buff;
            }
                 return ent_Employ._Insert_employee(employeeID, name, sex, birthDay, personID, dateOfIssue, placeOfIssue,hometown, email, mobile, addressE, salary, images, homePhone);
        }

        public DataSet SelectAll_Employee()
        {
            return ent_Employ._SelectAll_Employee();
        }

        //tìm kiếm theo tên
        public DataSet FindbyName(string name)
        {
            return ent_Employ._FindbyName(name);
        }
        public DataTable SelectOne_Employee(string id)
        {
            return ent_Employ._SelectOne_Employee(id).Tables[0];
        }

        public bool Delete_Employee(string id)
        {
            return ent_Employ._Delete_employee(id);
        }

        public bool Update_Employee(string employeeID, string name, int sex, string birthDay, string personID, string dateOfIssue, string placeOfIssue, string hometown, string email, string mobile, string addressE, string salary, byte[] images, string homePhone, string startupPath)
        {
            byte[] buff = null;
            if (images == null)
            //images = BitConverter.GetBytes(0);
            {
                FileStream files = new FileStream(startupPath + "\\NO_IMG.png", FileMode.Open);
                buff = new byte[files.Length];
                //Doc FileStream fs vua tao o tren vao mang byte[] buff
                files.Read(buff, 0, (int)files.Length);
                images = buff;
            }
            return ent_Employ._Update_Employee(employeeID, name, sex, birthDay, personID, dateOfIssue, placeOfIssue, hometown, email, mobile, addressE, salary, images, homePhone);
        }

        public DataSet ListUser()
        {
            return ent_Employ._ListUser();
        }

        public DataSet Select_AccType()
        {
            return ent_Employ._Select_AccType();
        }

        public DataSet Select_AcountOfType(string idType)
        {
            return ent_Employ._Select_AcountOfType(idType);
        }

        public DataSet Select_EmployAcc()
        {
            return ent_Employ._Select_EmployAcc();
        }

        public DataSet _Select_EmployNOTAcc()
        {
            return ent_Employ._Select_EmployNOTAcc();
        }



        public bool Insert_newAcc(string maNV, string id, string pass, string accType)
        {
            return ent_Employ._Insert_newAcc(maNV, id, pass, accType);
        }
    }
}
